package ShopManager;
import Method.Conexcute;

import java.io.IOException;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
@WebServlet(urlPatterns = "/Addshop")
@MultipartConfig(location = "D:\\picture")// location改为本地的绝对路径
public class AddshopServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String name= request.getParameter("name");
        String text=request.getParameter("text");
        Part part=request.getPart("image");
        String fileName = part.getSubmittedFileName();
        part.write(fileName);
        String image="D:\\picture\\"+fileName;
        Conexcute conexcute=new Conexcute();
        if(conexcute.execute("insert into `shop` (`sh_name`,`text`,`sh_image`) values ( '"+name+"', '"+text+"','"+image+"');")){
            response.setContentType("text/html");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().println("数据添加成功");
            response.sendRedirect("ShopManager/shop.jsp");
        }
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
